﻿//#include <iostream>
#include <fstream>
#include "BaseCommon.h"
#include <iomanip>
#include <boost/algorithm/string.hpp>
#include "DatWriteBack.h"

using namespace std;
using namespace JGG;

DatWriteBack::DatWriteBack(const char* database,
	int caseid,
	std::vector <std::string> Zone,
	std::vector <double> Voltage,
	std::string InFile,
	std::string OutFile)
{
	this->database = database;
	this->caseid = caseid;
	this->Zone = Zone;
	this->Voltage = Voltage;
	this->InFile = InFile;
	this->OutFile = OutFile;
}

DatWriteBack::DatWriteBack(const char* database, int caseid, std::string outFile)
{
    this->database = database;
    this->caseid = caseid;
    this->OutFile = outFile;
}

DatWriteBack::~DatWriteBack()
{
}

void DatWriteBack::GetN_1DatFromDb()
{
	std::string basename= GetBaseName();
	std::string ctrlinfor = GetCtrlInfor();

	//get n-1 dat file
	//$trace_p("获取N-1计算的dat文件");
	OutFile = OutFile.replace(0, 0, "./bpa_temp/static_analysis_temp/");

	ofstream ofile(OutFile.c_str(), ios::trunc | ios::out | ios::in);
	ofile << setiosflags(ios::left);

	ofile << ctrlinfor << endl;
	ofile << "/OUTAGE_SIM\\" << endl;
	ofile << ">OLD_BASE,FILE=" << basename << "<" << endl;

	int N_1OutZoneInputNum = Zone.size();
	if (N_1OutZoneInputNum == 0)
	{
		ofile << ">OUTAGE,";
	}
	else
	{
		ofile << ">OUTAGE,ZONES=";
		for (int i = 0; i < N_1OutZoneInputNum; i++)
		{
			if (i == N_1OutZoneInputNum - 1)
				ofile << Zone[i] << " ";
			else
				ofile << Zone[i] << ",";
		}
	}

	char str[8];
	ofile << "BASES=";
	if (Voltage[0] == Voltage[1])
	{
		sprintf_s(str, "%.1f", Voltage[0]);
		ofile << str << "<" << endl;
	}
	else
	{
		sprintf_s(str, "%.1f", Voltage[0]);
		ofile << str << ",";
		sprintf_s(str, "%.1f", Voltage[1]);
		ofile << str << "<" << endl;
	}
	ofile << ">DEFAULT_RATING<" << endl;
	ofile << ">OUTPUT_SORT,BOTH<\n\n(END)";
	ofile.flush();
	ofile.close();
}

string DatWriteBack::GetBaseName()
{
	SqliteHelperDataBase db;
	SqliteHelperBuffer bufSQL;
	db.open(database);

	//get base name
	bufSQL.format("select * from FileList where caseid = '%d';", caseid);
	SqliteHelperTable FileList = db.getTable(bufSQL);
	FileList.setRow(0);
	string BaseName = FileList.getStringField(3);
	db.close();

	return BaseName;
}

string DatWriteBack::GetCtrlInfor()
{
	SqliteHelperDataBase db;
	SqliteHelperBuffer bufSQL;
	db.open(database);

	//get control information
	bufSQL.format("select * from ContrInforList where caseid='%d' and ContrID=1;", caseid);
	SqliteHelperTable N_1ContrInfor = db.getTable(bufSQL);
	N_1ContrInfor.setRow(0);
	string CtrlInfor = N_1ContrInfor.getStringField(4);
	db.close();

	return CtrlInfor;
}

void DatWriteBack::GetBaseDatFromDb(std::vector <Line> AnnotateLines)
{
	int StopNum, ControlID;
	bool ThirdFlag = false;
	SqliteHelperDataBase db;
	SqliteHelperBuffer bufSQL;
	db.open(database);
	//稍后需要考虑没有找到的情况
	bufSQL.format(" select * from FileList where  caseid = (%d);", caseid);			//找出属于这个方案的文件
	SqliteHelperTable Table_FileList = db.getTable(bufSQL);
	string FileName = Table_FileList.getStringField(0);
	//公共信息（供查询）
	bufSQL.format(" select * from BusList where  caseid = (%d);", caseid);			//筛出该母线公共信息
	SqliteHelperTable Table_BusList = db.getTable(bufSQL);
	bufSQL.format(" select * from LineList where  caseid = (%d);", caseid);			//筛出该线路公共信息
	SqliteHelperTable Table_LineList = db.getTable(bufSQL);
	bufSQL.format(" select * from ZoneList where  caseid = (%d);", caseid);			//筛出该分区信息
	SqliteHelperTable Table_ZoneList = db.getTable(bufSQL);

	//数据修改卡
	bufSQL.format(" select * from PZCardList where  caseid = (%d);", caseid);	//PZ卡信息
	SqliteHelperTable Table_PZCardList = db.getTable(bufSQL);
	//控制语句
	bufSQL.format(" select * from ContrInforList where  caseid = (%d);", caseid);//控制语句
	SqliteHelperTable Table_ContrInforList = db.getTable(bufSQL);
	//I卡
	bufSQL.format(" select * from ICardList where  caseid = (%d);", caseid);
	SqliteHelperTable Table_ICardList = db.getTable(bufSQL);
	//A卡
	bufSQL.format(" select * from ACardDatBaseList where  caseid = (%d);", caseid);
	SqliteHelperTable Table_ACardList = db.getTable(bufSQL);
	//各个卡片的数量
	int ContrInforNum, PZNum;
	int ICardNum, ACardNum;
	ContrInforNum = Table_ContrInforList.numRows();
	PZNum = Table_PZCardList.numRows();
	ICardNum = Table_ICardList.numRows();
	ACardNum = Table_ACardList.numRows();

	OutFile = OutFile.replace(0, 0, "./bpa_temp/static_analysis_temp/");
	ofstream ofile((OutFile).c_str(), ios::out);
	ofile << setiosflags(ios::left);

	string StrTmp;
	//0-1控制语句输出(：：基准功率的转换需要考虑)
	//输出结束语句、三级控制语句之前的控制语句
	for (ControlID = 0; ControlID < ContrInforNum - 1; ControlID++)
	{
		Table_ContrInforList.setRow(ControlID);
		StrTmp = Table_ContrInforList.getStringField(4);
		if (StrTmp.find("CHAN") == -1 && StrTmp.find("SOLU") == -1)
			ofile << Table_ContrInforList.getStringField(4) << endl;
		else
			break;
	}
	StopNum = ControlID;
	//A卡
	for (int i = 0; i<ACardNum; i++)
	{
		Table_ACardList.setRow(i);
		ofile << 'A' << "  " << setw(10) << Table_ACardList.getStringField(3)
			<< setw(8) << Table_ACardList.getStringField(4);
		ofile << setw(4) << Table_ACardList.getFloatField(5);
		ofile << ' ';
		if (Table_ACardList.getFloatField(6) == 999999)				//交换功率
			ofile << setw(4) << " " << setw(4) << " ";
		else
			ofile << setw(8) << Table_ACardList.getFloatField(6);
		ofile << ' ';
		ofile << setw(2) << Table_ACardList.getStringField(7) << ' ';
		ofile << setw(2) << Table_ACardList.getStringField(8) << ' ';
		ofile << setw(2) << Table_ACardList.getStringField(9) << ' ';
		ofile << setw(2) << Table_ACardList.getStringField(10) << ' ';
		ofile << setw(2) << Table_ACardList.getStringField(11) << ' ';
		ofile << setw(2) << Table_ACardList.getStringField(12) << ' ';
		ofile << setw(2) << Table_ACardList.getStringField(13) << ' ';
		ofile << setw(2) << Table_ACardList.getStringField(14) << ' ';
		ofile << setw(2) << Table_ACardList.getStringField(15) << ' ';
		ofile << setw(2) << Table_ACardList.getStringField(16) << ' ';
		ofile << setw(2) << Table_ACardList.getStringField(17) << ' ';
		ofile << setw(2) << Table_ACardList.getStringField(18) << ' ';
		ofile << setw(2) << Table_ACardList.getStringField(19) << ' ';
		ofile << setw(2) << Table_ACardList.getStringField(20) << ' ';
		ofile << setw(2) << Table_ACardList.getStringField(21) << ' ';
		ofile << setw(2) << Table_ACardList.getStringField(22) << ' ';
		ofile << setw(2) << Table_ACardList.getStringField(23) << ' ';
		ofile << setw(2) << Table_ACardList.getStringField(24) << ' ';
		ofile << setw(2) << Table_ACardList.getStringField(25) << ' ';
		ofile << setw(2) << Table_ACardList.getStringField(26) << ' ';
		ofile << endl;
		StrTmp = Table_ACardList.getStringField(27);
		if (StrTmp != "")					//转换成AC+
		{
			ofile << "AC+" << setw(10) << Table_ACardList.getStringField(3);
			ofile << setw(6) << " " << setw(6) << " " << setw(6) << " " << setw(4) << " ";
			ofile << setw(2) << Table_ACardList.getStringField(27) << ' ';
			ofile << setw(2) << Table_ACardList.getStringField(28) << ' ';
			ofile << setw(2) << Table_ACardList.getStringField(29) << ' ';
			ofile << setw(2) << Table_ACardList.getStringField(30) << ' ';
			ofile << setw(2) << Table_ACardList.getStringField(31) << ' ';
			ofile << setw(2) << Table_ACardList.getStringField(32) << ' ';
			ofile << setw(2) << Table_ACardList.getStringField(33) << ' ';
			ofile << setw(2) << Table_ACardList.getStringField(34) << ' ';
			ofile << setw(2) << Table_ACardList.getStringField(35) << ' ';
			ofile << setw(2) << Table_ACardList.getStringField(36) << ' ';
			ofile << setw(2) << Table_ACardList.getStringField(37) << ' ';
			ofile << setw(2) << Table_ACardList.getStringField(38) << ' ';
			ofile << setw(2) << Table_ACardList.getStringField(39) << ' ';
			ofile << setw(2) << Table_ACardList.getStringField(40) << ' ';
			ofile << setw(2) << Table_ACardList.getStringField(41) << ' ';
			ofile << setw(2) << Table_ACardList.getStringField(42) << ' ';
			ofile << setw(2) << Table_ACardList.getStringField(43) << ' ';
			ofile << setw(2) << Table_ACardList.getStringField(44) << ' ';
			ofile << setw(2) << Table_ACardList.getStringField(45) << ' ';
			ofile << setw(2) << Table_ACardList.getStringField(46) << ' ';
			ofile << endl;
		}
	}
	//I卡
	for (int i = 0; i<ICardNum; i++)
	{
		Table_ICardList.setRow(i);
		ofile << 'I' << "  " << setw(10) << Table_ICardList.getStringField(3)
			<< ' ' << setw(10) << Table_ICardList.getStringField(4) << "  ";
		if (Table_ICardList.getFloatField(5) == 999999)				//联络线总的交换功率值
			ofile << setw(4) << " " << setw(4) << " ";
		else
			ofile << setw(8) << Table_ICardList.getStringField(5);
		ofile << endl;
	}
	//叠加变量
	int iBusNormal = 0;					//节点类
	int iBusBD = 0;
	int iLineNormal = 0;				//线路类
	int iLineDC = 0;
	int iLineLX = 0;
	int iLineE = 0;						//不对称线路类
	int iTransform = 0;					//变压器类
	int iBpaNote = 0;					//注释语句类
	int iPlus = 0;							//+A卡
	int BusNormalNum, BDNum, LineNormalNum, LineLDNum, LineENum, LineLXNum, TransNum, BpaNoteNum;

	stringstream oss;
	//普通交流节点
	oss.str("");
	oss << "select * from busnormallist a,buslist b where a.[BusID] = b.[BusID] "
		<< "and a.[caseid] = b.[caseid] and a.[caseid] = " << caseid << " group by a.[BusID];";
	//筛出普通母线信息
	SqliteHelperTable Table_BusNormalList = db.getTable(oss.str().c_str());
	BusNormalNum = Table_BusNormalList.numRows();
	//直流节点
	oss.str("");
	oss << "select * from BusBDList a,buslist b where a.[BusID] = b.[BusID] "
		<< "and a.[caseid] = b.[caseid] and a.[caseid] = " << caseid << " group by a.[BusID];";
	//筛出直流母线信息
	SqliteHelperTable Table_BusBDList = db.getTable(oss.str().c_str());
	BDNum = Table_BusBDList.numRows();
	//普通交流线路
	oss.str("");
	oss << "select * from LineNormalList a,lineList b where a.[LineID] = b.[LineID] "
		<< "and a.[caseid] = b.[caseid] and a.[caseid] = " << caseid << " group by a.[LineID];";
	//筛出该普通线路信息
	SqliteHelperTable Table_LineNormalList = db.getTable(oss.str().c_str());
	LineNormalNum = Table_LineNormalList.numRows();
	//直流线路
	oss.str("");
	oss << "select * from LineDCList a,lineList b where a.[LineID] = b.[LineID] "
		<< "and a.[caseid] = b.[caseid] and a.[caseid] = " << caseid << " group by a.[LineID];";
	//筛出直流线路信息
	SqliteHelperTable Table_LineDCList = db.getTable(oss.str().c_str());
	LineLDNum = Table_LineDCList.numRows();
	//高抗线路
	oss.str("");
	oss << "select * from LineLXList a,lineList b where a.[LineID] = b.[LineID] "
		<< "and a.[caseid] = b.[caseid] and a.[caseid] = " << caseid << " group by a.[LineID];";
	//筛出高抗信息
	SqliteHelperTable Table_LineLXList = db.getTable(oss.str().c_str());
	LineLXNum = Table_LineLXList.numRows();
	//不对称线路
	oss.str("");
	oss << "select * from LineEList where  caseid = " << caseid << ";";
	//筛出不对称信息
	SqliteHelperTable Table_LineEList = db.getTable(oss.str().c_str());
	LineENum = Table_LineEList.numRows();
	//变压器
	oss.str("");
	oss << "select * from Transform_2List where  caseid = " << caseid << ";";
	//筛出该变压器信息（含带负荷调节）
	SqliteHelperTable Table_Transform_2List = db.getTable(oss.str().c_str());
	TransNum = Table_Transform_2List.numRows();
	//注释语句
	oss.str("");
	oss << "select * from BpaNote where  caseid = " << caseid << ";";
	//筛出该变压器信息（含带负荷调节）
	SqliteHelperTable Table_BpaNote = db.getTable(oss.str().c_str());
	BpaNoteNum = Table_BpaNote.numRows();
	//+A卡
	oss.str("");
	oss << "select * from Plus_AList a,BusList b where (a.[BusID] = b.[BusID]) "
		<< "and a.[caseid] = " << caseid << " group by a.[BusID];";
	//筛出普通母线信息
	SqliteHelperTable Table_Plus_AList = db.getTable(oss.str().c_str());
	int nPlus = Table_Plus_AList.numRows();
	//待输出的总数
	int nOutPut;
	nOutPut = BusNormalNum + BDNum + LineNormalNum + LineLDNum + LineLXNum + LineENum + TransNum + BpaNoteNum + nPlus;
	bool  BpaNoteFlag = false;			//0
	bool BusNormalFlag = false;			//1
	bool BusBDFlg = false;				//2
	bool LineNormalFlag = false;		//3
	bool LineDCFlag = false;			//4
	bool LineLXFlag = false;			//5
	bool LineEFlag = false;				//6
	bool TransformFlag = false;			//7
	bool Plus_AFlag = false;			//8
	string BusNameTmp;					//处理字符串中有“'”的情况
	int nLineID[9];
	if (BpaNoteNum)
	{
		Table_BpaNote.setRow(0);
		nLineID[0] = Table_BpaNote.getIntField(0);
	}
	else
	{
		nLineID[0] = 0;
	}
	//网络中的普通节点不可能没有
	Table_BusNormalList.setRow(0);
	nLineID[1] = Table_BusNormalList.getIntField(16);
	if (BDNum)
	{
		Table_BusBDList.setRow(0);
		nLineID[2] = Table_BusBDList.getIntField(11);
	}
	else
	{
		nLineID[2] = 0;
	}
	Table_LineNormalList.setRow(0);
	nLineID[3] = Table_LineNormalList.getIntField(22);
	if (LineLDNum)
	{
		Table_LineDCList.setRow(0);
		nLineID[4] = Table_LineDCList.getIntField(14);
	}
	else
	{
		nLineID[4] = 0;
	}
	if (LineLXNum)
	{
		Table_LineLXList.setRow(0);
		nLineID[5] = Table_LineLXList.getIntField(5);
	}
	else
	{
		nLineID[5] = 0;
	}
	if (LineENum)
	{
		Table_LineEList.setRow(0);
		nLineID[6] = Table_LineEList.getIntField(0);
	}
	else
	{
		nLineID[6] = 0;
	}
	if (TransNum)
	{
		Table_Transform_2List.setRow(0);
		nLineID[7] = Table_Transform_2List.getIntField(0);
	}
	else
		nLineID[7] = 0;
	if (nPlus)
	{
		Table_Plus_AList.setRow(0);
		nLineID[8] = Table_Plus_AList.getIntField(0);
	}
	else
		nLineID[8] = 0;
	int IDmin, indexMin;
	for (int iOut = 0; iOut < nOutPut; iOut++)
	{
		if (nLineID[0] > 0)
		{
			IDmin = nLineID[0];
			indexMin = 0;
		}
		else if (nLineID[1] > 0)
		{
			IDmin = nLineID[1];
			indexMin = 1;
		}
		else if (nLineID[2] > 0)
		{
			IDmin = nLineID[2];
			indexMin = 2;
		}
		else if (nLineID[3] > 0)
		{
			IDmin = nLineID[3];
			indexMin = 3;
		}
		else if (nLineID[4] > 0)
		{
			IDmin = nLineID[4];
			indexMin = 4;
		}
		else if (nLineID[5] > 0)
		{
			IDmin = nLineID[5];
			indexMin = 5;
		}
		else if (nLineID[6] > 0)
		{
			IDmin = nLineID[6];
			indexMin = 6;
		}
		else if (nLineID[7] > 0)
		{
			IDmin = nLineID[7];
			indexMin = 7;
		}
		else if (nLineID[8] > 0)
		{
			IDmin = nLineID[8];
			indexMin = 8;
		}
		else
			break;
		//寻找出非0元素中nLineID[]中的最小值,并记录下标
		for (int idex = indexMin + 1; idex < 9; idex++)
		{
			if (nLineID[idex])
			{
				if (nLineID[idex] < IDmin)
				{
					IDmin = nLineID[idex];
					indexMin = idex;
				}
			}
		}
		switch (indexMin)
		{
		case 0:
		{
			BpaNoteFlag = true;
			break;
		}
		case 1:
		{
			BusNormalFlag = true;
			break;
		}
		case 2:
		{
			BusBDFlg = true;
			break;
		}
		case 3:
		{
			LineNormalFlag = true;
			break;
		}
		case 4:
		{
			LineDCFlag = true;
			break;
		}
		case 5:
		{
			LineLXFlag = true;
			break;
		}
		case 6:
		{
			LineEFlag = true;
			break;
		}
		case 7:
		{
			TransformFlag = true;
			break;
		}
		case 8:
		{
			Plus_AFlag = true;
			break;
		}
		default:	break;
		}
		//当最小行号表是注释行时
		if (BpaNoteFlag)
		{
			//Table_BpaNote.setRow(iBpaNote);
			BusNameTmp = Table_BpaNote.getStringField(2);
			boost::replace_all(BusNameTmp, "$", "'");
			ofile << BusNameTmp << endl;
			BpaNoteFlag = false;
			iBpaNote++;
			if (iBpaNote < BpaNoteNum)
			{
				Table_BpaNote.setRow(iBpaNote);
				nLineID[0] = Table_BpaNote.getIntField(0);
			}
			else
				nLineID[0] = 0;
		}
		//当最小行号是普通交流节点时
		if (BusNormalFlag)
		{
			//Table_BusNormalList.setRow(i);
			Table_BusList.setRow(Table_BusNormalList.getIntField(1) - 1);		//查询母线基础信息
			BusNameTmp = Table_BusList.getStringField(6);
			boost::replace_all(BusNameTmp, "$", "'");
			ofile << setw(2) << Table_BusList.getStringField(5) << ' ' << setw(3) << Table_BusList.getStringField(8) << setw(8) << BusNameTmp;
			if (Table_BusList.getFloatField(7) < 1)
				ofile << setw(4) << ZeroDelet(Table_BusList.getFloatField(7), 3);
			else
				ofile << setw(4) << Table_BusList.getFloatField(7);
			if (Table_BusList.getIntField(4) != 0)								//能够查询到分区
			{
				Table_ZoneList.setRow(Table_BusList.getIntField(4) - 1);		//查询分区基础信息
				ofile << setw(2) << Table_ZoneList.getStringField(5);
			}
			else
				ofile << "  ";
			if (Table_BusNormalList.getFloatField(3) == 999999)
				ofile << setw(5) << " ";
			else
			{
				if (abs(Table_BusNormalList.getFloatField(3)) < 1)						//有功
				{
					if (Table_BusNormalList.getFloatField(3) > 0)
						ofile << setw(5) << ZeroDelet(Table_BusNormalList.getFloatField(3), 4);
					else
						ofile << setw(5) << ZeroDelet(Table_BusNormalList.getFloatField(3), 3);
				}
				else
					ofile << setw(5) << Table_BusNormalList.getFloatField(3);
			}
			if (Table_BusNormalList.getFloatField(4) == 999999)
				ofile << setw(5) << " ";
			else
			{
				if (abs(Table_BusNormalList.getFloatField(4)) < 1)						//无功
				{
					if (Table_BusNormalList.getFloatField(4) > 0)
						ofile << setw(5) << ZeroDelet(Table_BusNormalList.getFloatField(4), 4);
					else
						ofile << setw(5) << ZeroDelet(Table_BusNormalList.getFloatField(4), 3);
				}
				else
					ofile << setw(5) << Table_BusNormalList.getFloatField(4);
			}
			if (Table_BusNormalList.getFloatField(5) == 999999)						//并联有功
				ofile << setw(4) << " ";
			else
				ofile << setw(4) << Table_BusNormalList.getFloatField(5);
			if (Table_BusNormalList.getFloatField(6) == 999999)						//并联无功
				ofile << setw(4) << " ";
			else
				ofile << setw(4) << Table_BusNormalList.getFloatField(6);
			if (Table_BusNormalList.getFloatField(7) == 999999)						//最大有功
				ofile << setw(4) << " ";
			else
				ofile << setw(4) << Table_BusNormalList.getFloatField(7);
			if (Table_BusNormalList.getFloatField(8) == 999999)						//实际有功
				ofile << setw(5) << " ";
			else
			{
				if (fabs(Table_BusNormalList.getFloatField(8)) < 1)
					ofile << setw(5) << ZeroDelet(Table_BusNormalList.getFloatField(8), 4);
				else
					ofile << setw(5) << Table_BusNormalList.getFloatField(8);
			}
			if (Table_BusNormalList.getFloatField(9) == 999999)						//无功出力最大值	
				ofile << setw(5) << " ";
			else
				ofile << setw(5) << Table_BusNormalList.getFloatField(9);
			if (Table_BusNormalList.getFloatField(10) == 999999)						//无功出力最小值
				ofile << setw(5) << " ";
			else
			{
				if (Table_BusNormalList.getFloatField(10) == 0)
					ofile << setw(5) << "0.";
				else
				{
					if (abs(Table_BusNormalList.getFloatField(10)) < 1)
					{
						if (Table_BusNormalList.getFloatField(10) > 0)
							ofile << setw(5) << ZeroDelet(Table_BusNormalList.getFloatField(10), 4);
						else
							ofile << setw(5) << ZeroDelet(Table_BusNormalList.getFloatField(10), 3);
					}
					else
						ofile << setw(5) << Table_BusNormalList.getFloatField(10);
				}
			}
			if (Table_BusNormalList.getFloatField(11) == 999999)						//安排电压值
				ofile << setw(4) << " ";
			else
				ofile << setw(4) << (Table_BusNormalList.getFloatField(11) * 1000);
			if (Table_BusNormalList.getFloatField(12) == 999999)
				ofile << setw(4) << " ";
			else
			{
				if (Table_BusList.getStringField(5) != "BS")							//平衡节点代表的是角度（有名值）
					ofile << setw(4) << (Table_BusNormalList.getFloatField(12) * 1000);
				else
				{
					if (floor(Table_BusNormalList.getFloatField(12)) - Table_BusNormalList.getFloatField(12) == 0)
						ofile << setw(4) << PointRight(Table_BusNormalList.getFloatField(12));
					else
					{
						if (Table_BusNormalList.getFloatField(12) > 10)
							ofile << setw(4) << Table_BusNormalList.getFloatField(12);
						else
							ofile << setw(4) << (Table_BusNormalList.getFloatField(12) * 1000);
					}
				}
			}
			if (Table_BusNormalList.getFloatField(13) == 1)							//是BG母线
			{
				Table_BusList.setRow(Table_BusNormalList.getIntField(14) - 1);		//查询母线基础信息
				ofile << setw(8) << Table_BusList.getStringField(6);
				if (Table_BusList.getFloatField(7) < 1)
					ofile << setw(4) << ZeroDelet(Table_BusList.getFloatField(7), 3);
				else
					ofile << setw(4) << Table_BusList.getFloatField(7);
				if (Table_BusNormalList.getIntField(15) == 999999)
					ofile << "   ";
				else
					ofile << Table_BusNormalList.getIntField(15);
			}
			ofile << endl;
			BusNormalFlag = false;
			iBusNormal++;
			if (iBusNormal < BusNormalNum)
			{
				Table_BusNormalList.setRow(iBusNormal);
				nLineID[1] = Table_BusNormalList.getIntField(16);
			}
			else
				nLineID[1] = 0;
		}
		//当最小行号是直流节点时
		if (BusBDFlg)
		{
			//Table_BusBDList.setRow(i);
			Table_BusList.setRow(Table_BusBDList.getIntField(1) - 1);		//查询母线基础信息
			BusNameTmp = Table_BusList.getStringField(6);
			boost::replace_all(BusNameTmp, "$", "'");
			ofile << setw(2) << Table_BusList.getStringField(5) << ' ' << setw(3) << Table_BusList.getStringField(8) << setw(8) << BusNameTmp;
			if (Table_BusList.getFloatField(7) < 1)
				ofile << setw(4) << ZeroDelet(Table_BusList.getFloatField(7), 3);
			else
				ofile << setw(4) << Table_BusList.getFloatField(7);
			if (Table_BusList.getIntField(4) != 0)								//能够查询到分区
			{
				Table_ZoneList.setRow(Table_BusList.getIntField(4) - 1);	//查询分区基础信息
				ofile << setw(2) << Table_ZoneList.getStringField(5);
			}
			else
				ofile << setw(2) << " ";
			ofile << setw(3) << " ";
			ofile << setw(2) << Table_BusBDList.getIntField(2);		//整流桥数
			if (Table_BusBDList.getFloatField(3) == 999999)				//平波电抗器电感
				ofile << setw(5) << " ";
			else
				ofile << setw(5) << (Table_BusBDList.getFloatField(3) * 10);
			if (Table_BusBDList.getFloatField(4) == 999999)				//整流器最小触发角
				ofile << setw(5) << " ";
			else
				ofile << setw(5) << (Table_BusBDList.getIntField(4) * 10);
			if (Table_BusBDList.getFloatField(5) == 999999)				//逆变器最大触发角
				ofile << setw(5) << " ";
			else
				ofile << setw(5) << (Table_BusBDList.getFloatField(5) * 10);
			if (Table_BusBDList.getFloatField(6) == 999999)				//桥阀压降
				ofile << setw(5) << " ";
			else
				ofile << setw(5) << (Table_BusBDList.getFloatField(6) * 10);
			if (Table_BusBDList.getFloatField(7) == 999999)				//桥电流额定值
				ofile << setw(5) << " ";
			else
				ofile << setw(5) << (Table_BusBDList.getFloatField(7) * 10);
			Table_BusList.setRow(Table_BusBDList.getIntField(10) - 1);		//查询母线基础信息
			BusNameTmp = Table_BusList.getStringField(6);
			boost::replace_all(BusNameTmp, "$", "'");
			ofile << setw(8) << BusNameTmp << setw(4) << Table_BusList.getFloatField(7);	//换流节点名、基压
			ofile << endl;
			BusBDFlg = false;
			iBusBD++;
			if (iBusBD < BDNum)
			{
				Table_BusBDList.setRow(iBusBD);
				nLineID[2] = Table_BusBDList.getIntField(11);
			}
			else
				nLineID[2] = 0;
		}
		//最小行号是普通交流节点
		if (LineNormalFlag)
		{
			for (int i = 0; i < AnnotateLines.size(); i++)
			{
				if (Table_LineNormalList.getIntField(25) == AnnotateLines[i].StartNum
					&& Table_LineNormalList.getIntField(26) == AnnotateLines[i].EndNum
					&& Table_LineNormalList.getStringField(15) == AnnotateLines[i].ShuntFlag)
				{
					ofile << ".";			//注释掉该语句
				}
				else
				{
					//定位行数
					Table_LineList.setRow(Table_LineNormalList.getIntField(1) - 1);//查询基础信息	
					Table_BusList.setRow(Table_LineList.getIntField(3) - 1);		//定位到始端母线
					BusNameTmp = Table_BusList.getStringField(6);
					boost::replace_all(BusNameTmp, "$", "'");
					ofile << "L " << ' ' << setw(3) << Table_LineList.getStringField(7) << setw(8) << BusNameTmp;
					if (Table_BusList.getFloatField(7) < 1)
						ofile << setw(4) << ZeroDelet(Table_BusList.getFloatField(7), 3);
					else
						ofile << setw(4) << Table_BusList.getFloatField(7);
					ofile << Table_LineNormalList.getStringField(16);			//测点
					Table_BusList.setRow(Table_LineList.getIntField(4) - 1);		//定位到末端母线	
					BusNameTmp = Table_BusList.getStringField(6);
					boost::replace_all(BusNameTmp, "$", "'");
					ofile << setw(8) << BusNameTmp;
					if (Table_BusList.getFloatField(7) < 1)
						ofile << setw(4) << ZeroDelet(Table_BusList.getFloatField(7), 3);
					else
						ofile << setw(4) << Table_BusList.getFloatField(7);
					ofile << Table_LineNormalList.getStringField(15);			//并联标志
					ofile << Table_LineNormalList.getStringField(18);			//线路串号
					if (Table_LineNormalList.getFloatField(2) == 999999)				//额定电流
						ofile << setw(4) << " ";
					else
						ofile << setw(4) << Table_LineNormalList.getFloatField(2);
					ofile << Table_LineNormalList.getStringField(17);			//并联数目
					if (Table_LineNormalList.getFloatField(3) == 999999)				//线路电阻
						ofile << setw(6) << " ";
					else
						ofile << setw(6) << (Table_LineNormalList.getFloatField(3) * pow(10.0, 5));
					if (Table_LineNormalList.getFloatField(6) == 999999)				//线路电抗
						ofile << setw(6) << " ";
					else
					{
						if (Table_LineNormalList.getFloatField(6) == 99999)
							ofile << "99999.";
						else
							ofile << setw(6) << (Table_LineNormalList.getFloatField(6) * pow(10.0, 5));
					}
					if (Table_LineNormalList.getFloatField(9) == 999999)				//线路电导
						ofile << setw(6) << " ";
					else
						ofile << setw(6) << (Table_LineNormalList.getFloatField(9) * pow(10.0, 5));
					if (Table_LineNormalList.getFloatField(12) == 999999)				//线路电纳(12.221)
						ofile << setw(6) << " ";
					else
					{
						if (Table_LineNormalList.getFloatField(12) >= 10)
							ofile << setw(6) << Table_LineNormalList.getFloatField(12);
						else
							ofile << setw(6) << (Table_LineNormalList.getFloatField(12) * pow(10.0, 5));
					}
					if (Table_LineList.getFloatField(5) == 999999)						//线路长度F4.1(145.7、60,30.7,8.82)
						ofile << setw(4) << " ";
					else
					{
						if (floor(Table_LineList.getFloatField(5)) - Table_LineList.getFloatField(5) == 0)
							ofile << setw(4) << PointRight(Table_LineList.getFloatField(5));
						else
						{
							if (Table_LineList.getFloatField(5) < 10)
								ofile << setw(4) << Table_LineList.getFloatField(5);
							else
								ofile << setw(4) << (Table_LineList.getFloatField(5) * 10);
						}
					}
					ofile << setw(4) << " " << setw(4) << " " << setw(3) << " " << setw(3) << " ";
					//输出注释信息
					if (Table_LineNormalList.getStringField(19) != "NULL")
						ofile << Table_LineNormalList.getStringField(19);
				}
			}

			ofile << endl;
			LineNormalFlag = false;
			iLineNormal++;
			if (iLineNormal < LineNormalNum)
			{
				Table_LineNormalList.setRow(iLineNormal);
				nLineID[3] = Table_LineNormalList.getIntField(22);
			}
			else
				nLineID[3] = 0;
		}
		if (LineDCFlag)
		{
			//Table_LineDCList.setRow(i);										//定位行数
			Table_LineList.setRow(Table_LineDCList.getIntField(1) - 1);	//查询基础信息	
			Table_BusList.setRow(Table_LineList.getIntField(3) - 1);		//定位到始端母线
			BusNameTmp = Table_BusList.getStringField(6);
			boost::replace_all(BusNameTmp, "$", "'");
			ofile << "LD" << ' ' << setw(3) << Table_LineList.getStringField(7) << setw(8) << BusNameTmp;
			if (Table_BusList.getFloatField(7) < 1)
				ofile << setw(4) << ZeroDelet(Table_BusList.getFloatField(7), 3);
			else
				ofile << setw(4) << Table_BusList.getFloatField(7);
			ofile << Table_LineDCList.getStringField(11);				//测点标志
			Table_BusList.setRow(Table_LineList.getIntField(4) - 1);		//定位到末端母线
			BusNameTmp = Table_BusList.getStringField(6);
			boost::replace_all(BusNameTmp, "$", "'");
			ofile << setw(8) << BusNameTmp;
			if (Table_BusList.getFloatField(7) < 1)
				ofile << setw(4) << ZeroDelet(Table_BusList.getFloatField(7), 3);
			else
				ofile << setw(4) << Table_BusList.getFloatField(7);
			ofile << "  ";
			if (Table_LineDCList.getFloatField(2) == 999999)					//额定电流
				ofile << setw(4) << " ";
			else
				ofile << setw(4) << Table_LineDCList.getFloatField(2);
			if (Table_LineDCList.getFloatField(3) == 999999)					//直流电阻(F6.2,26.082,0.001)
				ofile << setw(6) << " ";
			else
			{
				if (floor(Table_LineDCList.getFloatField(3)) - Table_LineDCList.getFloatField(3) == 0)
					ofile << setw(6) << PointRight(Table_LineDCList.getFloatField(3));
				else
					ofile << setw(6) << Table_LineDCList.getFloatField(3);
			}
			if (Table_LineDCList.getFloatField(4) == 999999)						//直流电感
				ofile << setw(6) << " ";
			else
				ofile << setw(6) << (Table_LineDCList.getFloatField(4) * 100);
			if (Table_LineDCList.getFloatField(5) == 999999)						//直流电容
				ofile << setw(6) << " ";
			else
				ofile << setw(6) << (Table_LineDCList.getFloatField(5) * 100);
			ofile << Table_LineDCList.getStringField(6);						//控制点
			if (Table_LineDCList.getFloatField(7) == 999999)						//直流功率
				ofile << setw(5) << " ";
			else
				ofile << setw(5) << (Table_LineDCList.getFloatField(7) * 10);
			if (Table_LineDCList.getFloatField(8) == 999999)						//直流电压
				ofile << setw(5) << " ";
			else
				ofile << setw(5) << (Table_LineDCList.getFloatField(8) * 10);
			if (Table_LineDCList.getFloatField(9) == 999999)						//整流触发角
				ofile << setw(4) << " ";
			else
				ofile << setw(4) << (Table_LineDCList.getFloatField(9) * 10);
			if (Table_LineDCList.getFloatField(10) == 999999)						//逆变关断角
				ofile << setw(4) << " ";
			else
				ofile << setw(4) << (Table_LineDCList.getFloatField(10) * 10);
			if (Table_LineList.getFloatField(5) == 999999)						//线路长度
				ofile << setw(4) << " ";
			else
				ofile << setw(4) << Table_LineList.getFloatField(5);
			ofile << endl;
			LineDCFlag = false;
			iLineDC++;
			if (iLineDC < LineLDNum)
			{
				Table_LineDCList.setRow(iLineDC);
				nLineID[4] = Table_LineDCList.getIntField(14);
			}
			else
				nLineID[4] = 0;
		}
		if (LineLXFlag)
		{
			//Table_LineLXList.setRow(i);									//定位行数
			Table_LineList.setRow(Table_LineLXList.getIntField(1) - 1);//查询基础信息	
			Table_BusList.setRow(Table_LineList.getIntField(3) - 1);		//定位到始端母线
			BusNameTmp = Table_BusList.getStringField(6);
			boost::replace_all(BusNameTmp, "$", "'");
			ofile << "L+" << ' ' << setw(3) << Table_LineList.getStringField(7) << setw(8) << BusNameTmp;
			if (Table_BusList.getFloatField(7) < 1)
				ofile << setw(4) << ZeroDelet(Table_BusList.getFloatField(7), 3);
			else
				ofile << setw(4) << Table_BusList.getFloatField(7);
			ofile << " ";
			Table_BusList.setRow(Table_LineList.getIntField(4) - 1);		//定位到末端母线
			BusNameTmp = Table_BusList.getStringField(6);
			boost::replace_all(BusNameTmp, "$", "'");
			ofile << setw(8) << BusNameTmp;
			if (Table_BusList.getFloatField(7) < 1)
				ofile << setw(4) << ZeroDelet(Table_BusList.getFloatField(7), 3);
			else
				ofile << setw(4) << Table_BusList.getFloatField(7);
			ofile << Table_LineLXList.getStringField(4);
			ofile << " ";
			if (Table_LineLXList.getFloatField(2) == 999999)					//前侧高抗容量
				ofile << setw(5) << " ";
			else
				ofile << setw(5) << Table_LineLXList.getFloatField(2);
			ofile << setw(5) << " ";
			if (Table_LineLXList.getFloatField(3) == 999999)					//后侧高抗容量
				ofile << setw(5) << " ";
			else
				ofile << setw(5) << Table_LineLXList.getFloatField(3);
			ofile << endl;
			LineLXFlag = false;
			iLineLX++;
			if (iLineLX < LineLXNum)
			{
				Table_LineLXList.setRow(iLineLX);
				nLineID[5] = Table_LineLXList.getIntField(5);
			}
			else
				nLineID[5] = 0;
		}
		if (LineEFlag)
		{
			//LineEFlag = false;
			//Table_LineEList.setRow(i);										//定位行数
			Table_BusList.setRow(Table_LineEList.getIntField(3) - 1);		//定位到始端母线
			BusNameTmp = Table_BusList.getStringField(6);
			boost::replace_all(BusNameTmp, "$", "'");
			ofile << "E " << ' ' << setw(3) << Table_LineEList.getStringField(29) << setw(8) << BusNameTmp;
			if (Table_BusList.getFloatField(7) < 1)
				ofile << setw(4) << ZeroDelet(Table_BusList.getFloatField(7), 3);
			else
				ofile << setw(4) << Table_BusList.getFloatField(7);
			ofile << Table_LineEList.getStringField(28);					//测点
			Table_BusList.setRow(Table_LineEList.getIntField(4) - 1);		//定位到末端母线
			BusNameTmp = Table_BusList.getStringField(6);
			boost::replace_all(BusNameTmp, "$", "'");
			ofile << setw(8) << BusNameTmp;
			if (Table_BusList.getFloatField(7) < 1)
				ofile << setw(4) << ZeroDelet(Table_BusList.getFloatField(7), 3);
			else
				ofile << setw(4) << Table_BusList.getFloatField(7);
			ofile << Table_LineEList.getStringField(27);				//并联标志
			ofile << " ";
			if (Table_LineEList.getFloatField(8) == 999999)				//额定电流
				ofile << setw(4) << " ";
			else
				ofile << setw(4) << Table_LineEList.getFloatField(8);
			ofile << " ";
			if (Table_LineEList.getFloatField(9) == 999999)				//线路电阻
				ofile << setw(6) << " ";
			else
				ofile << setw(6) << (Table_LineEList.getFloatField(9) * pow(10.0, 5));
			if (Table_LineEList.getFloatField(12) == 999999)				//线路电抗
				ofile << setw(6) << " ";
			else
				ofile << setw(6) << (Table_LineEList.getFloatField(12) * pow(10.0, 5));
			if (Table_LineEList.getFloatField(15) == 999999)				//线路电导1
				ofile << setw(6) << " ";
			else
				ofile << setw(6) << (Table_LineEList.getFloatField(15) * pow(10.0, 5));
			if (Table_LineEList.getFloatField(18) == 999999)				//电纳1
				ofile << setw(6) << " ";
			else
			{
				if (Table_LineEList.getFloatField(18) > 0)
					ofile << setw(6) << (Table_LineEList.getFloatField(18) * pow(10.0, 5));
				else
				{
					if (abs(Table_LineEList.getFloatField(18)) > 1)
						ofile << setw(6) << Table_LineEList.getFloatField(18);
					else
						ofile << setw(6) << (Table_LineEList.getFloatField(18) * pow(10.0, 5));
				}
			}
			if (Table_LineEList.getFloatField(21) == 999999)						//电导2
				ofile << setw(6) << " ";
			else
				ofile << setw(6) << (Table_LineEList.getFloatField(21) * pow(10.0, 5));
			if (Table_LineEList.getFloatField(24) == 999999)						//电纳2(存在负值)
				ofile << setw(6) << " ";
			else
			{
				if (Table_LineEList.getFloatField(24) > 0)
					ofile << setw(6) << (Table_LineEList.getFloatField(24) * pow(10.0, 5));
				else
				{
					if (abs(Table_LineEList.getFloatField(24)) > 1)
						ofile << setw(6) << Table_LineEList.getFloatField(24);
					else
						ofile << setw(6) << (Table_LineEList.getFloatField(24) * pow(10.0, 5));
				}
			}
			ofile << endl;
			LineEFlag = false;
			iLineE++;
			if (iLineE < LineENum)
			{
				Table_LineEList.setRow(iLineE);
				nLineID[6] = Table_LineEList.getIntField(0);
			}
			else
				nLineID[6] = 0;
		}
		if (TransformFlag)
		{
			//Table_Transform_2List.setRow(i);									//定位行数
			Table_BusList.setRow(Table_Transform_2List.getIntField(3) - 1);	//定位到始端母线
			BusNameTmp = Table_BusList.getStringField(6);
			boost::replace_all(BusNameTmp, "$", "'");
			ofile << setw(2) << Table_Transform_2List.getStringField(5) << ' ' << setw(3) << Table_Transform_2List.getStringField(38) << setw(8) << BusNameTmp;
			if (Table_BusList.getFloatField(7) < 1)
				ofile << setw(4) << ZeroDelet(Table_BusList.getFloatField(7), 3);
			else
				ofile << setw(4) << Table_BusList.getFloatField(7);
			ofile << Table_Transform_2List.getStringField(35);				//测点
			Table_BusList.setRow(Table_Transform_2List.getIntField(4) - 1);	//定位到末端母线
			BusNameTmp = Table_BusList.getStringField(6);
			boost::replace_all(BusNameTmp, "$", "'");
			ofile << setw(8) << BusNameTmp;
			if (Table_BusList.getFloatField(7) < 1)
				ofile << setw(4) << ZeroDelet(Table_BusList.getFloatField(7), 3);
			else
				ofile << setw(4) << Table_BusList.getFloatField(7);
			ofile << Table_Transform_2List.getStringField(34);					//考虑并联标志
			ofile << Table_Transform_2List.getStringField(37);					//线路串号
			if (Table_Transform_2List.getFloatField(6) == 999999)						//变压器容量
				ofile << setw(4) << " ";
			else
				ofile << setw(4) << Table_Transform_2List.getFloatField(6);
			ofile << Table_Transform_2List.getStringField(36);					//并联数目
			if (Table_Transform_2List.getFloatField(7) == 999999)					   //变压器电阻
				ofile << setw(6) << " ";
			else
			{
				if (floor(Table_Transform_2List.getFloatField(7)) - Table_Transform_2List.getFloatField(7) == 0)
					ofile << setw(6) << PointRight(Table_Transform_2List.getFloatField(7));
				else
				{
					if (Table_Transform_2List.getFloatField(7) < 0)			//(-2.1)
					{
						if (abs(Table_Transform_2List.getFloatField(7)) > 1)
							ofile << setw(6) << Table_Transform_2List.getFloatField(7);
						else
							ofile << setw(6) << (Table_Transform_2List.getFloatField(7) * pow(10.0, 5));
					}
					else
					{
						if (Table_Transform_2List.getFloatField(7) > 10)
							ofile << setw(6) << Table_Transform_2List.getFloatField(7);
						else
							ofile << setw(6) << (Table_Transform_2List.getFloatField(7) * pow(10.0, 5));
					}
				}

			}
			if (Table_Transform_2List.getFloatField(10) == 999999)					//变压器电抗（考虑负值）
				ofile << setw(6) << " ";
			else
			{
				if (floor(Table_Transform_2List.getFloatField(10)) - Table_Transform_2List.getFloatField(10) == 0)
					ofile << setw(6) << PointRight(Table_Transform_2List.getFloatField(10));
				else
				{
					if (Table_Transform_2List.getFloatField(10) < 0)			//(-2.1)
					{
						if (abs(Table_Transform_2List.getFloatField(10))>1)
							ofile << setw(6) << Table_Transform_2List.getFloatField(10);
						else
							ofile << setw(6) << (Table_Transform_2List.getFloatField(10) * pow(10.0, 5));
					}
					else
					{
						if (Table_Transform_2List.getFloatField(10) > 10)
							ofile << setw(6) << Table_Transform_2List.getFloatField(10);
						else
							ofile << setw(6) << (Table_Transform_2List.getFloatField(10) * pow(10.0, 5));
					}
				}
			}
			if (Table_Transform_2List.getFloatField(13) == 999999)					   //变压器电导
				ofile << setw(6) << " ";
			else
				ofile << setw(6) << (Table_Transform_2List.getFloatField(13) * pow(10.0, 5));
			if (Table_Transform_2List.getFloatField(16) == 999999)					   //变压器电纳
				ofile << setw(6) << " ";
			else
				ofile << setw(6) << (Table_Transform_2List.getFloatField(16) * pow(10.0, 5));
			if (Table_Transform_2List.getFloatField(19) == 999999)					   //变压器抽头1(9.725)
				ofile << setw(5) << " ";
			else
			{
				if (floor(Table_Transform_2List.getFloatField(19)) - Table_Transform_2List.getFloatField(19) == 0)
					ofile << setw(5) << PointRight(Table_Transform_2List.getFloatField(19));
				else
				{
					if (Table_Transform_2List.getFloatField(19) < 10)						//F5.2（0.182、9.725）
						ofile << setw(5) << Table_Transform_2List.getFloatField(19);
					else
						ofile << setw(5) << (Table_Transform_2List.getFloatField(19) * 100);
				}
			}
			if (Table_Transform_2List.getFloatField(22) == 999999)					   //变压器抽头2
				ofile << setw(5) << " ";
			else
			{
				if (floor(Table_Transform_2List.getFloatField(22)) - Table_Transform_2List.getFloatField(22) == 0)
					ofile << setw(5) << PointRight(Table_Transform_2List.getFloatField(22));
				else
				{
					if (Table_Transform_2List.getFloatField(22) < 10)
						ofile << setw(5) << Table_Transform_2List.getFloatField(22);
					else
						ofile << setw(5) << (Table_Transform_2List.getFloatField(22) * 100);
				}
			}
			ofile << "           " << Table_Transform_2List.getStringField(46);
			ofile << endl;
			if (Table_Transform_2List.getFloatField(25) == 1)		//如果是带负荷调节变压器
			{
				Table_BusList.setRow(Table_Transform_2List.getIntField(3) - 1);	//定位到始端母线
				ofile << "R " << setw(4) << " " << setw(8) << Table_BusList.getStringField(6);
				if (Table_BusList.getFloatField(7) < 1)
					ofile << setw(4) << ZeroDelet(Table_BusList.getFloatField(7), 3);
				else
					ofile << setw(4) << Table_BusList.getFloatField(7);
				if (Table_Transform_2List.getIntField(28) == 0)					//可调抽头端
					ofile << " ";
				else
					ofile << Table_Transform_2List.getIntField(28);
				Table_BusList.setRow(Table_Transform_2List.getIntField(4) - 1);	//定位到末端母线
				ofile << setw(8) << Table_BusList.getStringField(6);
				if (Table_BusList.getFloatField(7) < 1)
					ofile << setw(4) << ZeroDelet(Table_BusList.getFloatField(7), 3);
				else
					ofile << setw(4) << Table_BusList.getFloatField(7);
				ofile << "  ";
				Table_BusList.setRow(Table_Transform_2List.getIntField(45) - 1);	//定位到始端母线
				BusNameTmp = Table_BusList.getStringField(6);
				boost::replace_all(BusNameTmp, "$", "'");
				ofile << setw(8) << BusNameTmp << setw(4) << Table_BusList.getFloatField(7);	//受控母线
				if (Table_Transform_2List.getFloatField(29) == 999999)						//最大抽头或者角度
					ofile << setw(5) << " ";
				else
				{
					if (floor(Table_Transform_2List.getFloatField(29)) - Table_Transform_2List.getFloatField(29) == 0)
						ofile << setw(5) << PointRight(Table_Transform_2List.getFloatField(29));
					else
						ofile << setw(5) << (Table_Transform_2List.getFloatField(29) * 100);
				}
				if (Table_Transform_2List.getFloatField(30) == 999999)						//最小抽头或者角度
					ofile << setw(5) << " ";
				else
					ofile << setw(5) << (Table_Transform_2List.getFloatField(30) * 100);
				if (Table_Transform_2List.getIntField(31) == 0)								//抽头数或档数
					ofile << "  ";
				else
					ofile << setw(2) << Table_Transform_2List.getIntField(31);
				if (Table_Transform_2List.getFloatField(32) == 999999)							//安排无功、有功最大
					ofile << setw(5) << " ";
				else
					ofile << setw(5) << Table_Transform_2List.getFloatField(32);
				if (Table_Transform_2List.getFloatField(33) == 999999)						//安排无功、有功最小
					ofile << setw(5) << " ";
				else
					ofile << setw(5) << Table_Transform_2List.getFloatField(33);
				ofile << endl;
			}
			TransformFlag = false;
			iTransform++;
			if (iTransform < TransNum)
			{
				Table_Transform_2List.setRow(iTransform);
				nLineID[7] = Table_Transform_2List.getIntField(0);
			}
			else
				nLineID[7] = 0;
		}
		if (Plus_AFlag)
		{
			BusNameTmp = Table_Plus_AList.getStringField(17);
			boost::replace_all(BusNameTmp, "$", "'");
			ofile << "+A" << ' ' << setw(3) << Table_Plus_AList.getStringField(3) << setw(8) << BusNameTmp << setw(4) << Table_Plus_AList.getFloatField(18);
			ofile << setw(2) << Table_Plus_AList.getStringField(4);
			if (Table_Plus_AList.getFloatField(5) == 999999)
				ofile << setw(5) << setw(5) << " ";
			else
				ofile << setw(5) << Table_Plus_AList.getFloatField(5);
			if (Table_Plus_AList.getFloatField(6) == 999999)
				ofile << setw(5) << setw(5) << " ";
			else
				ofile << setw(5) << Table_Plus_AList.getFloatField(6);
			if (Table_Plus_AList.getFloatField(7) == 999999)
				ofile << setw(5) << setw(4) << " ";
			else
				ofile << setw(5) << Table_Plus_AList.getFloatField(7);
			if (Table_Plus_AList.getFloatField(8) == 999999)
				ofile << setw(5) << setw(4) << " ";
			else
				ofile << setw(5) << Table_Plus_AList.getFloatField(8);
			if (Table_Plus_AList.getFloatField(9) == 999999)
				ofile << setw(5) << setw(5) << " ";
			else
				ofile << setw(5) << Table_Plus_AList.getFloatField(9);
			if (Table_Plus_AList.getFloatField(9) == 999999)
				ofile << setw(5) << setw(5) << " ";
			else
				ofile << setw(5) << Table_Plus_AList.getFloatField(9);
			ofile << endl;
			Plus_AFlag = false;
			iPlus++;
			if (iPlus < nPlus)
			{
				Table_Plus_AList.setRow(iPlus);
				nLineID[8] = Table_Plus_AList.getIntField(0);
			}
			else
				nLineID[8] = 0;
		}
	}
	//数据修改卡
	if (PZNum != 0)
	{
		ofile << "/CHANGES" << '\\' << endl;			//控制语句的输出
		for (int i = 0; i<PZNum; i++)
		{
			Table_PZCardList.setRow(i);
			if (Table_PZCardList.getIntField(3) != 0)							//考虑误输入的问题
			{
				Table_ZoneList.setRow(Table_PZCardList.getIntField(3) - 1);		//查询分区基础信息
				ofile << "PZ" << ' ' << setw(2) << Table_ZoneList.getStringField(5) << setw(4) << " ";
				if (Table_PZCardList.getFloatField(4) >= 1)	//有功负荷修改因子
					ofile << setw(5) << Table_PZCardList.getFloatField(4) << ' ';
				else
					ofile << setw(5) << ZeroDelet(Table_PZCardList.getFloatField(4), 4) << ' ';
				if (Table_PZCardList.getFloatField(5) >= 1)	//无功负荷修改因子
					ofile << setw(5) << Table_PZCardList.getFloatField(5) << ' ';
				else
					ofile << setw(5) << ZeroDelet(Table_PZCardList.getFloatField(5), 4) << ' ';
				if (Table_PZCardList.getFloatField(6) >= 1)	//有功出力修改因子(.001)
					ofile << setw(5) << Table_PZCardList.getFloatField(6) << ' ';
				else
					ofile << setw(5) << ZeroDelet(Table_PZCardList.getFloatField(6), 4) << ' ';
				if (Table_PZCardList.getFloatField(7) >= 1)	//无功出力修改因子
					ofile << setw(5) << Table_PZCardList.getFloatField(7) << ' ';
				else
					ofile << setw(5) << ZeroDelet(Table_PZCardList.getFloatField(7), 4);
				ofile << endl;
			}
		}
	}
	//考虑三级控制语句
	for (int i = StopNum; i<ContrInforNum - 1; i++)
	{
		Table_ContrInforList.setRow(i);
		StrTmp = Table_ContrInforList.getStringField(4);
		if (ThirdFlag)
			ofile << Table_ContrInforList.getStringField(4) << endl;
		else if (StrTmp.find("SOLU") != -1)
		{
			ThirdFlag = true;
			ofile << Table_ContrInforList.getStringField(4) << endl;
		}
	}
	Table_ContrInforList.setRow(ContrInforNum - 1);
	ofile << Table_ContrInforList.getStringField(4) << endl;
	db.close();
}

string DatWriteBack::ZeroDelet(double Factor, int n)
{
	char str[8];
	string StrTemp;
	switch (n)
	{
	case 3:
		sprintf_s(str, "%.3f", Factor);
		break;
	case 4:
		sprintf_s(str, "%.4f", Factor);
		break;
	default: break;
	}
	StrTemp = str;
	boost::erase_first(StrTemp, "0");
	return StrTemp;
}

string DatWriteBack::PointRight(double Voltage)
{
	char buf1[_CVTBUFSIZE];
	string strtemp;
	_gcvt_s(buf1, _CVTBUFSIZE, Voltage, 6);
	strtemp = buf1;
	return strtemp;
}